package server

import (
	"github.com/golang/glog"
	_ "net/http/pprof"
	"cloud_worm/access/config"
	"net/http"
	"time"
	"sync"
)

func DiagnoseSrv(wg *sync.WaitGroup) {
	if config.ConfInst.LocalConfig.PprofEnable == false {
		return
	}

	go func(wg *sync.WaitGroup) {

		glog.Infof("start pprof server '%s:%s' loop.", config.ConfInst.LocalAddr, config.ConfInst.LocalConfig.PprofPort)

		wg.Add(1)
		httpSrv := &http.Server{
			Addr: config.ConfInst.LocalAddr + ":" + config.ConfInst.LocalConfig.PprofPort,
			Handler: nil,
			IdleTimeout: 90 * time.Second,
		}

		err := httpSrv.ListenAndServe()
		if err != nil {
			glog.Fatalf("pprof server start error: %s", err.Error())
		}
		wg.Done()
	}(wg)
}

